package com.tmsps.ne4Weixin.api;

import com.alibaba.fastjson.JSONObject;
import com.tmsps.ne4Weixin.beans.BaseBean;
import com.tmsps.ne4Weixin.config.WxConfig;
import com.tmsps.ne4Weixin.utils.HttpClient;

/**
 * 
 * @author zhangwei 396033084@qq.com MenuAPI 菜单API
 */
public class MenuConditionalAPI extends BaseAPI {
	private static final String CREATEDMENU = BaseURL.concat("/cgi-bin/menu/addconditional?access_token=%s");
	private static final String TRYMATCH = BaseURL.concat("/cgi-bin/menu/trymatch?access_token=%s");

	public MenuConditionalAPI(WxConfig config) {
		super(config);
	}

	public BaseBean createMenu(String menuJSON) {
		String result = HttpClient.postJson(String.format(CREATEDMENU, config.getAccessToken()), menuJSON);
		return JSONObject.parseObject(result, BaseBean.class);
	}

	//测试菜单接口
	public BaseBean tryMatch(String openid) {
		JSONObject json = new JSONObject();
		json.put("user_id", openid);
		String result = HttpClient.postJson(String.format(TRYMATCH, config.getAccessToken()), json.toJSONString());
		return JSONObject.parseObject(result, BaseBean.class);
	}

}
